package web.controller;

import hibernate.pojo.User;
import hibernate.util.HibernateUtil;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Transaction;
import org.hibernate.classic.Session;

import web.controller.address_telefon.CreateNewTelephoneBookController;

public class RegisterForANewVotingController {

	private static final Log logger = LogFactory.getLog(CreateNewTelephoneBookController.class);
	
	private String firstName;
	private String lastName;
	private String eMail;
	private String password;
	private String organization;
	private String jobFunction;
	private String votingIDNumbers;

	
	public RegisterForANewVotingController() {
		// TODO Auto-generated constructor stub
	}

	
	public String registerForVoting(){
		
		String pageToRedirect = "";
		
		if(!validateUserInput()){
			pageToRedirect = "";
			return pageToRedirect;
		}
		
		try {

			pageToRedirect = "registerForVotingSuccess";
			
		} catch (Exception exception) {
			logger.error("Yeni kullanici kaydederken hata olustu!", exception);
		}
		
		return pageToRedirect;
	}

	private void confirmRegistration() {
		// connect to database and update registration status
		
	}
	
	public String cancelRegisterForVoting(){
		
		String pageToRedirect = "";
		
		if(!validateUserInput()){
			pageToRedirect = "";
			return pageToRedirect;
		}
		
		try {

//			user = new User();
//			user.setFirstName(firstName);
//			user.setLastName(lastName);
//			user.setUserName(userName);
//			user.setPassword(password);
			
//			Session session = HibernateUtil.getSessionFactory().openSession();
//			Transaction transaction = session.beginTransaction();
//			session.save(user);
//			transaction.commit();
//			clearFields();
			pageToRedirect = "insertNewUserSuccess";
			
		} catch (Exception exception) {
			logger.error("Yeni kullanici kaydederken hata olustu!", exception);
		}
		
		return pageToRedirect;
	}
	
	private boolean validateUserInput(){
		
		return true;
	}
	
	private void clearFields(){
		firstName = "";
		lastName = "";
		password = "";
	}
	
	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}
	
	public String geteMail() {
		return eMail;
	}


	public void seteMail(String eMail) {
		this.eMail = eMail;
	}


	public String getOrganization() {
		return organization;
	}


	public void setOrganization(String organization) {
		this.organization = organization;
	}


	public String getJobFunction() {
		return jobFunction;
	}


	public void setJobFunction(String jobFunction) {
		this.jobFunction = jobFunction;
	}


	public String getVotingIDNumbers() {
		return votingIDNumbers;
	}


	public void setVotingIDNumbers(String votingIDNumbers) {
		this.votingIDNumbers = votingIDNumbers;
	}
	
}
